<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
    <style>
      .user {
        background-color: lightblue;
        margin: 10px;
      }
    </style>
</head>
<body>
    <div id="app"></div>
    <script id="template" type="plain/text">

        <div>
            {{#each list:index}}
                <div>

                    <span>
                        {{index + 1 }}
                    </span>
                    /
                    <span>
                        {{list.length}}
                    </span>

                    <User index="{{index}}" {{...this}} />

                </div>
            {{/each}}

        </div>

    </script>

    <script id="template-user" type="plain/text">

        <div class="user">
            index: {{index}}<br>
            name: {{name}}<br>
            age: {{age}}
        </div>

    </script>

    <script src="../dist/standard/dev/yox.js"></script>
    <script>
        var instance = new Yox({
            el: '#app',
            template: '#template',
            data: {
                list: [
                    {
                        name: 'name1',
                        age: 1
                    },
                    {
                        name: 'name2',
                    },
                    {
                        name: 'name3',
                        age: 3
                    },
                    {
                        name: 'name4',
                        age: 4
                    }
                ]
            },
            components: {
                User: {
                    template: '#template-user',
                    propTypes: {
                        name: {
                            type: 'string'
                        },
                        age: {
                            type: 'number'
                        },
                        index: {
                            type: 'number'
                        }
                    },
                    beforeUpdate: function () {
                        console.log('User beforeUpdate')
                    },
                    afterUpdate: function () {
                      console.log('User afterUpdate')
                    }
                }
            },
            beforeUpdate: function () {
              console.log('Root beforeUpdate')
            },
            afterUpdate: function () {
              console.log('Root afterUpdate')
            }
        });

    </script>
</body>
</html>
